package com.tencent.smtt.sdk.a;

import MTT.ThirdAppInfoNew;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import com.sangfor.kevinsawicki.http.HttpRequest;
import com.sangfor.ssl.service.setting.SystemConfiguration;
import com.tencent.smtt.sdk.TbsDownloadConfig;
import com.tencent.smtt.utils.TbsLog;
import com.tencent.smtt.utils.n;
import com.tencent.smtt.utils.s;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;
import org.ksoap2.transport.ServiceConnection;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class c extends Thread {
    final /* synthetic */ Context a;
    final /* synthetic */ ThirdAppInfoNew b;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public c(String str, Context context, ThirdAppInfoNew thirdAppInfoNew) {
        super(str);
        this.a = context;
        this.b = thirdAppInfoNew;
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        String str;
        StringBuilder sb;
        String str2;
        String sb2;
        String str3;
        if (Build.VERSION.SDK_INT < 8) {
            return;
        }
        JSONObject jSONObject = null;
        if (b.a == null) {
            try {
                b.a = "65dRa93L".getBytes("utf-8");
            } catch (UnsupportedEncodingException unused) {
                b.a = null;
                TbsLog.e("sdkreport", "Post failed -- get POST_DATA_KEY failed!");
            }
        }
        if (b.a == null) {
            sb2 = "Post failed -- POST_DATA_KEY is null!";
        } else {
            String str4 = "";
            String string = TbsDownloadConfig.getInstance(this.a).mPreferences.getString(TbsDownloadConfig.TbsConfigKey.KEY_DESkEY_TOKEN, "");
            if (TextUtils.isEmpty(string)) {
                str = "";
            } else {
                str4 = string.substring(0, string.indexOf("&"));
                str = string.substring(string.indexOf("&") + 1, string.length());
            }
            boolean z = TextUtils.isEmpty(str4) || str4.length() != 96 || TextUtils.isEmpty(str) || str.length() != 24;
            try {
                s a = s.a();
                if (z) {
                    str3 = a.b() + n.a().b();
                } else {
                    str3 = a.f() + str4;
                }
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str3).openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setConnectTimeout(ServiceConnection.DEFAULT_TIMEOUT);
                if (Build.VERSION.SDK_INT > 13) {
                    httpURLConnection.setRequestProperty("Connection", SystemConfiguration.CONFIG_EFLAG_CLOSE);
                }
                try {
                    jSONObject = b.c(this.b, this.a);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (jSONObject != null) {
                    try {
                        byte[] bytes = jSONObject.toString().getBytes("utf-8");
                        byte[] a2 = z ? n.a().a(bytes) : n.a(bytes, str);
                        httpURLConnection.setRequestProperty("Content-Type", HttpRequest.CONTENT_TYPE_FORM);
                        httpURLConnection.setRequestProperty(HttpRequest.HEADER_CONTENT_LENGTH, String.valueOf(a2.length));
                        try {
                            OutputStream outputStream = httpURLConnection.getOutputStream();
                            outputStream.write(a2);
                            outputStream.flush();
                            if (httpURLConnection.getResponseCode() == 200) {
                                return;
                            }
                            TbsLog.e("sdkreport", "Post failed -- not 200");
                            return;
                        } catch (Throwable th) {
                            sb = new StringBuilder();
                            sb.append("Post failed -- exceptions:");
                            sb.append(th.getMessage());
                            sb2 = sb.toString();
                            TbsLog.e("sdkreport", sb2);
                        }
                    } catch (Throwable unused2) {
                        return;
                    }
                }
                sb2 = "post -- jsonData is null!";
            } catch (IOException e2) {
                e = e2;
                sb = new StringBuilder();
                str2 = "Post failed -- IOException:";
                sb.append(str2);
                sb.append(e);
                sb2 = sb.toString();
                TbsLog.e("sdkreport", sb2);
            } catch (AssertionError e3) {
                e = e3;
                sb = new StringBuilder();
                str2 = "Post failed -- AssertionError:";
                sb.append(str2);
                sb.append(e);
                sb2 = sb.toString();
                TbsLog.e("sdkreport", sb2);
            } catch (NoClassDefFoundError e4) {
                e = e4;
                sb = new StringBuilder();
                str2 = "Post failed -- NoClassDefFoundError:";
                sb.append(str2);
                sb.append(e);
                sb2 = sb.toString();
                TbsLog.e("sdkreport", sb2);
            }
        }
        TbsLog.e("sdkreport", sb2);
    }
}
